﻿using UnityEngine;

namespace Framework
{
    public static class TransformHelper
    {
        private static Vector3 tempVec3;
        private static Vector2 tempVec2;
        private static Quaternion tempQua;

        public static void SetPos(this Transform transform, float x, float y, float z)
        {
            tempVec3.Set(x, y, z);
            transform.position = tempVec3;
        }

        public static void SetPosLerp(this Transform transform, float x, float y, float z, float lerp)
        {
            tempVec3.Set(x, y, z);
            transform.position = Vector3.Lerp(transform.position, tempVec3, lerp);
        }

        public static void SetPosXY(this Transform transform, float x, float y)
        {
            tempVec3.Set(x, y, transform.position.z);
            transform.position = tempVec3;
        }

        public static void GetPos(this Transform transform, out float x, out float y, out float z)
        {
            tempVec3 = transform.position;
            x = tempVec3.x;
            y = tempVec3.y;
            z = tempVec3.z;
        }

        public static void SetLocalPos(this Transform transform, float x, float y, float z)
        {
            tempVec3.Set(x, y, z);
            transform.localPosition = tempVec3;
        }

        public static void SetLocalPosLerp(this Transform transform, float x, float y, float z, float lerp)
        {
            tempVec3.Set(x, y, z);
            transform.localPosition = Vector3.Lerp(transform.localPosition, tempVec3, lerp);
        }

        public static void SetLocalPosXY(this Transform transform, float x, float y)
        {
            tempVec3.Set(x, y, transform.localPosition.z);
            transform.localPosition = tempVec3;
        }

        public static void GetLocalPos(this Transform transform, out float x, out float y, out float z)
        {
            tempVec3 = transform.localPosition;
            x = tempVec3.x;
            y = tempVec3.y;
            z = tempVec3.z;
        }

        public static void SetLocalScale(this Transform transform, float x, float y, float z)
        {
            tempVec3.Set(x, y, z);
            transform.localScale = tempVec3;
        }
        public static void SetLocalScaleLerp(this Transform transform, float x, float y, float z, float lerp)
        {
            tempVec3.Set(x, y, z);
            transform.localScale = Vector3.Lerp(transform.localScale, tempVec3, lerp);
        }

        public static void GetLocalScale(this Transform transform, out float x, out float y, out float z)
        {
            tempVec3 = transform.localScale;
            x = tempVec3.x;
            y = tempVec3.y;
            z = tempVec3.z;
        }
        public static void GetLossyScale(this Transform transform, out float x, out float y, out float z)
        {
            tempVec3 = transform.lossyScale;
            x = tempVec3.x;
            y = tempVec3.y;
            z = tempVec3.z;
        }

        public static void SetLocalEulerAngles(this Transform transform, float x, float y, float z)
        {
            tempVec3.Set(x, y, z);
            transform.localEulerAngles = tempVec3;
        }

        public static void GetLocalEulerAngles(this Transform transform, out float x, out float y, out float z)
        {
            tempVec3 = transform.localEulerAngles;
            x = tempVec3.x;
            y = tempVec3.y;
            z = tempVec3.z;
        }

        public static void SetEulerAngles(this Transform transform, float x, float y, float z)
        {
            tempVec3.Set(x, y, z);
            transform.eulerAngles = tempVec3;
        }

        public static void GetEulerAngles(this Transform transform, out float x, out float y, out float z)
        {
            tempVec3 = transform.eulerAngles;
            x = tempVec3.x;
            y = tempVec3.y;
            z = tempVec3.z;
        }
        public static void SetRotation(this Transform transform, float x, float y, float z, float w)
        {
            tempQua.Set(x, y, z, w);
            transform.rotation = tempQua;
        }
        public static void SetLocalRotation(this Transform transform, float x, float y, float z, float w)
        {
            tempQua.Set(x, y, z, w);
            transform.localRotation = tempQua;
        }
        public static void SetLocalRotationLerp(this Transform transform, float dstX, float dstY, float dstZ, float lerp)
        {
            transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.Euler(dstX, dstY, dstZ), lerp);
        }

        public static void SetRotationLerp(this Transform transform, float dstX, float dstY, float dstZ, float lerp)
        {
            transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(dstX, dstY, dstZ), lerp);
        }

        public static void GetForward(this Transform transform, out float x, out float y, out float z)
        {
            tempVec3 = transform.forward;
            x = tempVec3.x;
            y = tempVec3.y;
            z = tempVec3.z;
        }

        public static void GetUp(this Transform transform, out float x, out float y, out float z)
        {
            tempVec3 = transform.up;
            x = tempVec3.x;
            y = tempVec3.y;
            z = tempVec3.z;
        }

        public static void GetRight(this Transform transform, out float x, out float y, out float z)
        {
            tempVec3 = transform.right;
            x = tempVec3.x;
            y = tempVec3.y;
            z = tempVec3.z;
        }

        /// <summary>
        /// 本地坐标转世界坐标
        /// </summary>
        /// <param name="transform"></param>
        public static void LocalPosToWorldPos(this Transform transform, float in_x, float in_y, float in_z, out float x, out float y, out float z)
        {
            tempVec3.Set(in_x, in_y, in_z);
            tempVec3 = transform.TransformPoint(tempVec3);
            x = tempVec3.x;
            y = tempVec3.y;
            z = tempVec3.z;
        }

        /// <summary>
        /// 本地坐标转世界坐标
        /// </summary>
        /// <param name="transform"></param>
        public static void WorldPosToLocalPos(this Transform transform, float in_x, float in_y, float in_z, out float x, out float y, out float z)
        {
            tempVec3.Set(in_x, in_y, in_z);
            tempVec3 = transform.InverseTransformPoint(tempVec3);
            x = tempVec3.x;
            y = tempVec3.y;
            z = tempVec3.z;
        }
    }
}